-
Notifications
You must be signed in to change notification settings - Fork 118
Fix deadlock crash when updating UserDefaults #16256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see my comments, otherwise works as described.
| // Use dedicated serial queue for UserDefaults operations to: | ||
| // 1. Prevent race conditions where concurrent writes overwrite each other | ||
| // 2. Avoid deadlock by not using the main queue that KVO observers may need | ||
| userDefaultsQueue.async { [weak self] in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small note, as we are using async here notificationCenter might fire before the value is actually set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! I updated this in fc11138 and removed the waiting in tests.
| // Use dedicated serial queue for UserDefaults operations to: | ||
| // 1. Prevent race conditions where concurrent writes overwrite each other | ||
| // 2. Avoid deadlock by not using the main queue that KVO observers may need | ||
| userDefaultsQueue.async { [weak self] in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same concerc as above, clearUnsupportedFlag might return befire the value is set in UserDefault
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also done in fc11138.
…ecessary wait in tests

Closes WOOMOB-1524
Description
There is a crash report about a deadlock caused as part of the error handling when forcing direct requests for sites.
This deadlock is caused by updating
UserDefaultsinside the same queue we use for flagging site with barrier block. To be more specific,UserDefaultsuses Key-Value Observing (KVO), which delivers notifications synchronously. When we write toUserDefaultsinside a barrier block, the KVO observer fires before the barrier completes, and if that observer tries to access the same queue → deadlock.The solution is to fire updates to UserDefaults to a separate serial queue to avoid blocking the concurrent queue we use for error handling.
Testing steps
It's not straightforward to reproduce the deadlock. Simply smoke testing the flow should be sufficient.
Use the test plan in pe5sF9-4Am-p2 - run TC4. Confirm that the app doesn't crash.
Testing information
Screenshots
N/A
RELEASE-NOTES.txtif necessary.